package com.syh.jn.scm.domain.upstream.entity.base;

import cn.redscarf.commons.util.bean.ExtBeanUtils;
import com.syh.core.ddd.domain.AbstractSimpleAggregate;
import com.syh.core.ddd.domain.CodeExpEnum;
import com.syh.core.ddd.domain.CodeGenerateUtil;
import com.syh.jn.scm.dto.upstream.base.UpNewGoodsRequestMto;
import com.syh.jn.scm.dto.upstream.base.UpNewGoodsRequestSto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.UUID;

/**
 * 商品申请管理
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class UpNewGoodsRequest extends AbstractSimpleAggregate<Long> {

  /**
   * 新建商品申请
   *
   * @param sto
   */
  public UpNewGoodsRequest(UpNewGoodsRequestSto sto) {
    ExtBeanUtils.copyProperties(sto, this);

    //初始化数据
    this.uuid = UUID.randomUUID().toString();
    Long currentTimeMillis = System.currentTimeMillis();
    this.code = CodeGenerateUtil.applyCodeGenerate(CodeExpEnum.UP_GOODS_APPLY_EXP.getCodeExp(), sto.getUpStreamSupplierId());
    this.auditStatus = 0;
    this.createTimeStamp = currentTimeMillis;
    this.lastUpdateTimeStamp = currentTimeMillis;
  }

  /**
   * 修改商品申请信息
   *
   * @param mto
   */
  public void modify(UpNewGoodsRequestMto mto) {
    if (this.auditStatus == 1) {
      logger.error("modify:该商品审核已通过,不可以修改");
      throw new RuntimeException("该商品审核已通过,不可以修改");
    }
    ExtBeanUtils.copyProperties(mto, this);
    this.lastUpdateTimeStamp = System.currentTimeMillis();
  }

  /**
   * 删除商品申请
   */
  public void destroy() {

  }

  /**
   * 申请编号
   */
  private String code;
  /**
   * 商品名称
   */
  private String goodsName;
  /**
   * 联系人
   */
  private String contacts;
  /**
   * 联系人电话
   */
  private String mobile;
  /**
   * 商品品牌id
   */
  private Long goodsBrandId;
  /**
   * 商品描述
   */
  private String goodsDescription;
  /**
   * 图片url,保存格式json字符串["www.test.com","www.demo.com"]
   */
  private String imgUrl;
  /**
   * 审核: -1不通过,0未审核,1审核通过
   */
  private Short auditStatus;
  /**
   * 关联商品id
   */
  private Long associatedGoodsId;
  /**
   * 关联商品名称
   */
  private String associatedGoodsName;
  /**
   * 审核提交给哪个服务商ID
   */
  private Long supId;
  /**
   * 审核未通过描述
   */
  private String auditDescription;
  /**
   * 数据归属ID
   */
  private Long businessEntityId;
}
